760B - Frodo and pillows - CodeForces Solution


binary search greedy *1500

Please click on ads to support us..

Python Code:

n,m,k=map(int,input().split())
m-=n
d=0
k-=1
ans=1
while m>1 and d!=max(k,n-k-1):
  ans+=1
  m-=1
  l=min(d,k)
  r=min(d,n-k-1)
  d+=1
  m-=l
  m-=r
ans+=m//n
 
print(ans)

C++ Code:

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define pb push_back
#define FOR(n) for (int i = 0; i < n; i++)
#define FORj(n) for (int j = 0; j < n; j++)

void solve() {
    int n, m, k;cin >> n >> m >> k;

    int l = k, r = k;

    int ans = 1;
    m -= n;

    while (m >= (r - l + 1)) {
        ans++;
        m -= (r - l + 1);
        r = min(r + 1, n);
        l = max(l - 1, 1 );

        if (l == 1 && r == n) break;
    }

    ans += (m / n);

    cout << ans;
}

int main () {
    ios::sync_with_stdio(0); cin.tie(0);
    int T = 1;
    //cin >> T;
    while (T--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits